#!/bin/ksh

LOGIN=$1
SH_DIR=$2
UP_DIR=$3
UP_FILE=$4
BUSINESS=$5

sqlplus -s $LOGIN<<!
DELETE FROM ccs.ccs_ams_tmp_call_result;
COMMIT;
!

cat > $UP_DIR/ctl/Upload_CallResult.ctl<<!
LOAD DATA
INFILE '$UP_DIR/$UP_FILE'
APPEND INTO TABLE CCS.CCS_AMS_TMP_CALL_RESULT
TRAILING NULLCOLS
(
BUSINESS_TYPE			  CONSTANT							$BUSINESS,
BATCH_NO 				  POSITION(01:21)   CHAR		"TRIM(:BATCH_NO)",
ACCOUNT_NO				  POSITION(22:33)   CHAR		"TRIM(:ACCOUNT_NO)",
MOBILE_NO				  POSITION(34:41)   CHAR		"TRIM(:MOBILE_NO)",
CALL_COMPLETE_DATE	  POSITION(42:49)   DATE(8)	"yyyymmdd" NULLIF CALL_COMPLETE_DATE=BLANKS,
ASCERTAIN_SUBSCRIBER   POSITION(50:50)   CHAR		"TRIM(:ASCERTAIN_SUBSCRIBER)",
CALL_RESULT 			  POSITION(51:53)   CHAR		"TRIM(:CALL_RESULT)",
CALL_OUTCOME			  POSITION(54:56)   CHAR		"TRIM(:CALL_OUTCOME)",
SOURCE_FILE 			  CONSTANT							$UP_FILE
)
!

/usr/local/bin/dos2unix $UP_DIR/$UP_FILE
sqlldr $LOGIN \
control=$UP_DIR/ctl/Upload_CallResult.ctl bad=$UP_DIR/bad/Upload_CallResult.bad \
log=$UP_DIR/log/Upload_CallResult.log >> $UP_DIR/log/Upload_CallResult.log
